package com.bsy.videostation.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bsy.common.viewmodel.BaseViewModel
import com.bsy.framework.ext.data
import com.bsy.videostation.constant.loginName
import com.bsy.videostation.constant.loginPwd
import com.bsy.videostation.manager.UserServiceManager
import com.bsy.videostation.model.res.UserInfo
import com.bsy.videostation.repository.MainRepository

/**
 * Created by Sincerity on 2024/5/22.
 * Copyright
 * 描述：
 */
class SplashViewModel : BaseViewModel() {
    //用户信息
    val loginInfo = MutableLiveData<UserInfo>()
    private val loginRepository by lazy { MainRepository() }

    /**
     * 账号登录
     */
    fun loginByAccount() {
        launchUI(responseBlock = {
            val userInfo = loginRepository.passwordLogin(loginName, loginPwd)
            userInfo?.let {
                //保存token
                UserServiceManager.saveToken(it.token.data())
                UserServiceManager.saveUserInfo(it)
                UserServiceManager.saveLogin(true)
                loginInfo.value = it
            }
        })
    }
}